package sinoservices.hayden.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sinoservices.hayden.bean.Userinfo;
import sinoservices.hayden.service.UserInfoService;


import java.util.List;

@RestController
@RequestMapping("/userInfo")
public class userInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @PostMapping("/saveUser")
    public String saveUser(@RequestBody Userinfo userinfo){
        int i = userInfoService.saveUser(userinfo);
        if (i >= 0){
            return "增加成功";
        }else {
            return "增加失败";
        }
    }
    @GetMapping("/deleteUserById")
    public String deleteUserById (@RequestParam("id") int id){
        int i = userInfoService.deleteUserById(id);
        if (i >= 0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }
    @PostMapping("/updateUser")
    public String updateUser (@RequestBody Userinfo userinfo){
        int i = userInfoService.updateUser(userinfo);
        if (i >= 0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
    @GetMapping("/getUserInfo")
    @ResponseBody
    public Userinfo getUserInfo(@RequestParam("id") int id){
        return userInfoService.getUserInfo(id);
    }
    @PostMapping("/selectAllUser")
    @ResponseBody
    public List<Userinfo> selectAllUser (){
        return userInfoService.selectAllUser();
    }
}
